package magicloan.auctionpocket.decoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by hechao on 2018/1/27.
 */
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {

    private int space;

    public SpacesItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {

        if ( parent.getChildLayoutPosition(view)== 0 )
            return;

        outRect.bottom = space ;

        // Add top margin only for the first & seconde item to avoid double space between items  因为这是GrideView 所以是两次
        if (parent.getChildLayoutPosition(view) == 1 || parent.getChildLayoutPosition(view) == 2) {
            outRect.top = space ;
        } else {
            outRect.top = 0 ;
        }

        if ( parent.getChildLayoutPosition(view) %2 == 0 ){
            outRect.left = space ;
            outRect.right = space ;
        }else{
            outRect.left = space ;
        }

    }

}